using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using PocketLibrary;

namespace PocketApps
{
    public partial class NucleusTagging : Form
    {
        private BlogPost pTagPost = new BlogPost();
        private IBlog pBlog;

        public IBlog Blog
        {
            get { return pBlog; }
            set { pBlog = value; }
        }


        public BlogPost TagPost
        {
            get { return pTagPost; }
            set { pTagPost = value; }
        }

        public NucleusTagging()
        {
            InitializeComponent();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            PocketLibrary.Blog.NucleusPlugin.TagEX myTagEx = new PocketLibrary.Blog.NucleusPlugin.TagEX();
            myTagEx.UserName = pBlog.UserName;
            myTagEx.Password = pBlog.PassWord;
            myTagEx.PluginAPIEndPoint = "http://www.choomba.org/nucleusAPI.aspx";
            myTagEx.PostID = int.Parse(TagPost.postId);
            myTagEx.Tags.Clear();
            foreach (ListViewItem tagitems in listView1.Items)
            {
                if (tagitems.Checked)
                    myTagEx.Tags.Add(tagitems.Text);
            }

            myTagEx.addTagsV();
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void NucleusTagging_Load(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            textBox1.Text = TagPost.postTitle + "\r\n";
            textBox1.Text += TagPost.postBody;
            PocketLibrary.Blog.NucleusPlugin.TagEX myTagEx = new PocketLibrary.Blog.NucleusPlugin.TagEX();
            myTagEx.UserName = pBlog.UserName;
            myTagEx.Password = pBlog.PassWord;
            myTagEx.PluginAPIEndPoint = "http://www.choomba.org/nucleusAPI.aspx";
            myTagEx.getAllTags();
            foreach (string tag in myTagEx.Tags)
            {
                listView1.Items.Add(new ListViewItem(tag));
            }
        }

        private void bnAddTag_Click(object sender, EventArgs e)
        {
            if (tbNewTag.Text != "")
            {
                ListViewItem newTag = new ListViewItem();
                newTag.Text = tbNewTag.Text;
                listView1.Items.Add(newTag);
                tbNewTag.Text = "";
            }
        }
    }
}